package com.yuzou.十月力扣;

import java.util.ArrayDeque;
import java.util.Deque;

public class 每日温度 {
    public static void main(String[] args) {
        int[] dp = {73,74,75,71,69,72,76,73};
        int[] ans = dailyTemperatures(dp);
        for (int i = 0; i < ans.length; i++) {
            System.out.println(ans[i]);
        }
    }
    public static int[] dailyTemperatures(int[] T) {
        int n = T.length;
        int[] ans = new int[n];
        Deque< Integer> stack = new ArrayDeque<>();
        for (int i = 0;i < n; i++){
            while(!stack.isEmpty() && T[i] > T[stack.peek()]){
                int prev = stack.pop();
                ans[prev] = i - prev;
            }
            stack.push(i);//小于栈顶才入栈，所以当前维护的是递减栈；
        }
        return ans;
    }
}
